package com.ruoyi.zhgd.controller;

import java.util.*;

import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;

import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zhgd.domain.vo.NCementJwDataVo;
import com.ruoyi.zhgd.domain.bo.NCementJwDataBo;
import com.ruoyi.zhgd.service.INCementJwDataService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 水稳拌合站数据采集_2024-07-09_济微高速版
 *
 * @author zyb
 * @date 2024-09-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhgd/cementJwData")
public class NCementJwDataController extends BaseController {

    private final INCementJwDataService iNCementJwDataService;

    /**
     * 查询水稳拌合站数据采集_2024-07-09_济微高速版列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<NCementJwDataVo> list(NCementJwDataBo bo, PageQuery pageQuery) {
        return iNCementJwDataService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出水稳拌合站数据采集_2024-07-09_济微高速版列表
     */
    @SaCheckLogin
    @Log(title = "水稳拌合站数据采集_2024-07-09_济微高速版", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(NCementJwDataBo bo, HttpServletResponse response) {
        List<NCementJwDataVo> list = iNCementJwDataService.queryList(bo);
        ExcelUtil.exportExcel(list, "水稳拌合站数据采集_2024-07-09_济微高速版", NCementJwDataVo.class, response);
    }

    /**
     * 获取水稳拌合站数据采集_2024-07-09_济微高速版详细信息
     *
     * @param id 主键
     */
    @SaCheckLogin
    @GetMapping("/{id}")
    public R<NCementJwDataVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iNCementJwDataService.queryById(id));
    }

    /**
     * 新增水稳拌合站数据采集_2024-07-09_济微高速版
     */
    @SaCheckLogin
    @Log(title = "水稳拌合站数据采集_2024-07-09_济微高速版", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody NCementJwDataBo bo) {
        return toAjax(iNCementJwDataService.insertByBo(bo));
    }

    /**
     * 修改水稳拌合站数据采集_2024-07-09_济微高速版
     */
    @SaCheckLogin
    @Log(title = "水稳拌合站数据采集_2024-07-09_济微高速版", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody NCementJwDataBo bo) {
        return toAjax(iNCementJwDataService.updateByBo(bo));
    }

    /**
     * 删除水稳拌合站数据采集_2024-07-09_济微高速版
     *
     * @param ids 主键串
     */
    @SaCheckLogin
    @Log(title = "水稳拌合站数据采集_2024-07-09_济微高速版", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iNCementJwDataService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 查询水稳拌合站数据采集_2024-07-09_济微高速版列表
     */
    @SaCheckLogin
    @GetMapping("/homeData")
    public Map<String, Object> homeData(NCementJwDataBo bo) {
        return iNCementJwDataService.homeData(bo);
    }

    /**
     * 数据采集校验
     * @param id
     * @return
     */
    @SaIgnore
    @GetMapping("/isQualified")
    public R isQualified(@NotNull @RequestParam("id") String id) {
        // 等待数据采集完成后进行判定 等待时间 2分钟
        Timer timer = new Timer();
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                iNCementJwDataService.isQualified(id);
            }
        };
        timer.schedule(timerTask, 2 * 60 * 1000);
        return R.ok("", id);
    }

    /**
     * 手动校验
     * @param bo
     * @return
     */
    @SaCheckLogin
    @PostMapping("/handCheck")
    public R handCheck(@Validated(EditGroup.class) @RequestBody NCementJwDataBo bo) {
        iNCementJwDataService.handCheck(bo);
        return R.ok();
    }
}
